<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>权限管理 - 树形结构</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <style>
        .tree-container ul {
            list-style-type: none;
            padding-left: 1.5rem;
        }
        .tree-node {
            display: flex;
            align-items: center;
            padding: 0.5rem 0;
        }
        .tree-toggle {
            cursor: pointer;
            width: 24px;
            height: 24px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 0.5rem;
        }
        .tree-toggle.invisible {
            visibility: hidden;
        }
        .tree-label {
            cursor: pointer;
            display: flex;
            align-items: center;
        }
        .custom-checkbox {
            position: relative;
            display: inline-block;
            width: 18px;
            height: 18px;
            margin-right: 0.5rem;
        }
        .custom-checkbox input {
            opacity: 0;
            width: 0;
            height: 0;
        }
        .checkmark {
            position: absolute;
            top: 0;
            left: 0;
            height: 18px;
            width: 18px;
            background-color: #fff;
            border: 1px solid #d1d5db;
            border-radius: 3px;
        }
        .custom-checkbox input:checked ~ .checkmark {
            background-color: #4f46e5;
            border-color: #4f46e5;
        }
        .checkmark:after {
            content: "";
            position: absolute;
            display: none;
        }
        .custom-checkbox input:checked ~ .checkmark:after {
            display: block;
        }
        .custom-checkbox .checkmark:after {
            left: 6px;
            top: 2px;
            width: 5px;
            height: 10px;
            border: solid white;
            border-width: 0 2px 2px 0;
            transform: rotate(45deg);
        }
        .badge {
            font-size: 0.65rem;
            padding: 0.15rem 0.5rem;
            border-radius: 9999px;
            margin-left: 0.5rem;
        }
        .badge-menu {
            background-color: #dbeafe;
            color: #1e40af;
        }
        .badge-operation {
            background-color: #dcfce7;
            color: #166534;
        }
        .badge-data {
            background-color: #f3e8ff;
            color: #6b21a8;
        }
    </style>
</head>
<body class="bg-gray-50">
    <div class="container mx-auto px-4 py-6">
        <!-- 页面标题和操作按钮 -->
        <div class="flex justify-between items-center mb-6">
            <h1 class="text-2xl font-bold text-gray-800">权限管理</h1>
            <button class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded" onclick="openModal('addPermissionModal')">
                <i class="fas fa-plus mr-2"></i>添加权限
            </button>
        </div>

        <!-- 搜索和筛选 -->
        <div class="bg-white rounded-lg shadow-sm p-4 mb-6">
            <div class="grid grid-cols-1 md:grid-cols-4 gap-4">
                <div class="col-span-1">
                    <label class="block text-sm font-medium text-gray-700 mb-1">权限名称</label>
                    <input type="text" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" placeholder="请输入权限名称">
                </div>
                <div class="col-span-1">
                    <label class="block text-sm font-medium text-gray-700 mb-1">权限编码</label>
                    <input type="text" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" placeholder="请输入权限编码">
                </div>
                <div class="col-span-1">
                    <label class="block text-sm font-medium text-gray-700 mb-1">权限类型</label>
                    <select class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50">
                        <option value="">全部</option>
                        <option value="menu">菜单权限</option>
                        <option value="operation">操作权限</option>
                        <option value="data">数据权限</option>
                    </select>
                </div>
                <div class="col-span-1">
                    <label class="block text-sm font-medium text-gray-700 mb-1">所属模块</label>
                    <select class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50">
                        <option value="">全部</option>
                        <option value="system">系统管理</option>
                        <option value="user">用户管理</option>
                        <option value="hotel">酒店管理</option>
                        <option value="room">房间管理</option>
                        <option value="booking">预订管理</option>
                        <option value="finance">财务管理</option>
                    </select>
                </div>
            </div>
            <div class="flex justify-end mt-4">
                <button class="bg-gray-500 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded mr-2">
                    重置
                </button>
                <button class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded">
                    搜索
                </button>
            </div>
        </div>

        <!-- 权限树形结构 -->
        <div class="bg-white rounded-lg shadow-sm p-4">
            <div class="flex justify-between items-center mb-4">
                <h2 class="text-lg font-medium text-gray-900">权限列表</h2>
                <div>
                    <button class="text-indigo-600 hover:text-indigo-900 mr-2" onclick="expandAll()">
                        <i class="fas fa-expand-alt mr-1"></i>展开全部
                    </button>
                    <button class="text-indigo-600 hover:text-indigo-900">
                        <i class="fas fa-compress-alt mr-1"></i>折叠全部
                    </button>
                </div>
            </div>
            
            <div class="tree-container">
                <ul>
                    <!-- 系统管理 -->
                    <li>
                        <div class="tree-node">
                            <span class="tree-toggle" data-target="system-children">
                                <i class="fas fa-chevron-down"></i>
                            </span>
                            <label class="tree-label">
                                <span class="custom-checkbox">
                                    <input type="checkbox" class="tree-checkbox parent-checkbox" data-id="system">
                                    <span class="checkmark"></span>
                                </span>
                                <span class="font-medium">系统管理</span>
                            </label>
                        </div>
                        <ul id="system-children">
                            <!-- 角色管理 -->
                            <li>
                                <div class="tree-node">
                                    <span class="tree-toggle" data-target="role-children">
                                        <i class="fas fa-chevron-down"></i>
                                    </span>
                                    <label class="tree-label">
                                        <span class="custom-checkbox">
                                            <input type="checkbox" class="tree-checkbox child-checkbox" data-id="role" data-parent="system">
                                            <span class="checkmark"></span>
                                        </span>
                                        <span>角色管理</span>
                                    </label>
                                </div>
                                <ul id="role-children">
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="role-view" data-parent="role">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>查看角色</span>
                                                <span class="badge badge-menu">菜单权限</span>
                                            </label>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="role-create" data-parent="role">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>创建角色</span>
                                                <span class="badge badge-operation">操作权限</span>
                                            </label>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="role-edit" data-parent="role">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>编辑角色</span>
                                                <span class="badge badge-operation">操作权限</span>
                                            </label>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="role-delete" data-parent="role">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>删除角色</span>
                                                <span class="badge badge-operation">操作权限</span>
                                            </label>
                                        </div>
                                    </li>
                                </ul>
                            </li>
                            
                            <!-- 权限管理 -->
                            <li>
                                <div class="tree-node">
                                    <span class="tree-toggle" data-target="permission-children">
                                        <i class="fas fa-chevron-down"></i>
                                    </span>
                                    <label class="tree-label">
                                        <span class="custom-checkbox">
                                            <input type="checkbox" class="tree-checkbox child-checkbox" data-id="permission" data-parent="system">
                                            <span class="checkmark"></span>
                                        </span>
                                        <span>权限管理</span>
                                    </label>
                                </div>
                                <ul id="permission-children">
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="permission-view" data-parent="permission">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>查看权限</span>
                                                <span class="badge badge-menu">菜单权限</span>
                                            </label>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="permission-create" data-parent="permission">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>创建权限</span>
                                                <span class="badge badge-operation">操作权限</span>
                                            </label>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="permission-edit" data-parent="permission">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>编辑权限</span>
                                                <span class="badge badge-operation">操作权限</span>
                                            </label>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="permission-delete" data-parent="permission">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>删除权限</span>
                                                <span class="badge badge-operation">操作权限</span>
                                            </label>
                                        </div>
                                    </li>
                                </ul>
                            </li>
                            
                            <!-- 用户管理 -->
                            <li>
                                <div class="tree-node">
                                    <span class="tree-toggle" data-target="user-children">
                                        <i class="fas fa-chevron-down"></i>
                                    </span>
                                    <label class="tree-label">
                                        <span class="custom-checkbox">
                                            <input type="checkbox" class="tree-checkbox child-checkbox" data-id="user" data-parent="system">
                                            <span class="checkmark"></span>
                                        </span>
                                        <span>用户管理</span>
                                    </label>
                                </div>
                                <ul id="user-children">
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="user-view" data-parent="user">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>查看用户</span>
                                                <span class="badge badge-menu">菜单权限</span>
                                            </label>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="user-create" data-parent="user">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>创建用户</span>
                                                <span class="badge badge-operation">操作权限</span>
                                            </label>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="user-edit" data-parent="user">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>编辑用户</span>
                                                <span class="badge badge-operation">操作权限</span>
                                            </label>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="user-delete" data-parent="user">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>删除用户</span>
                                                <span class="badge badge-operation">操作权限</span>
                                            </label>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="user-reset-pwd" data-parent="user">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>重置密码</span>
                                                <span class="badge badge-operation">操作权限</span>
                                            </label>
                                        </div>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                    </li>
                    
                    <!-- 酒店管理 -->
                    <li>
                        <div class="tree-node">
                            <span class="tree-toggle" data-target="hotel-children">
                                <i class="fas fa-chevron-down"></i>
                            </span>
                            <label class="tree-label">
                                <span class="custom-checkbox">
                                    <input type="checkbox" class="tree-checkbox parent-checkbox" data-id="hotel">
                                    <span class="checkmark"></span>
                                </span>
                                <span class="font-medium">酒店管理</span>
                            </label>
                        </div>
                        <ul id="hotel-children">
                            <!-- 酒店信息 -->
                            <li>
                                <div class="tree-node">
                                    <span class="tree-toggle" data-target="hotel-info-children">
                                        <i class="fas fa-chevron-down"></i>
                                    </span>
                                    <label class="tree-label">
                                        <span class="custom-checkbox">
                                            <input type="checkbox" class="tree-checkbox child-checkbox" data-id="hotel-info" data-parent="hotel">
                                            <span class="checkmark"></span>
                                        </span>
                                        <span>酒店信息</span>
                                    </label>
                                </div>
                                <ul id="hotel-info-children">
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="hotel-view" data-parent="hotel-info">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>查看酒店</span>
                                                <span class="badge badge-menu">菜单权限</span>
                                            </label>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="hotel-add" data-parent="hotel-info">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>添加酒店</span>
                                                <span class="badge badge-operation">操作权限</span>
                                            </label>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="hotel-edit" data-parent="hotel-info">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>编辑酒店</span>
                                                <span class="badge badge-operation">操作权限</span>
                                            </label>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="hotel-delete" data-parent="hotel-info">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>删除酒店</span>
                                                <span class="badge badge-operation">操作权限</span>
                                            </label>
                                        </div>
                                    </li>
                                </ul>
                            </li>
                            
                            <!-- 房间管理 -->
                            <li>
                                <div class="tree-node">
                                    <span class="tree-toggle" data-target="room-children">
                                        <i class="fas fa-chevron-down"></i>
                                    </span>
                                    <label class="tree-label">
                                        <span class="custom-checkbox">
                                            <input type="checkbox" class="tree-checkbox child-checkbox" data-id="room" data-parent="hotel">
                                            <span class="checkmark"></span>
                                        </span>
                                        <span>房间管理</span>
                                    </label>
                                </div>
                                <ul id="room-children">
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="room-view" data-parent="room">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>查看房间</span>
                                                <span class="badge badge-menu">菜单权限</span>
                                            </label>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="tree-node">
                                            <span class="tree-toggle invisible">
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                            <label class="tree-label">
                                                <span class="custom-checkbox">
                                                    <input type="checkbox" class="tree-checkbox leaf-checkbox" data-id="room-add" data-parent="room">
                                                    <span class="checkmark"></span>
                                                </span>
                                                <span>添加房间</span>
                                                <span class="badge badge-operation">操作权限</span>
                                            </label>
                                        </div>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </div>

    <!-- 添加权限模态框 -->
    <div id="addPermissionModal" class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full hidden">
        <div class="relative top-20 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white">
            <div class="flex justify-between items-center mb-4">
                <h3 class="text-lg font-medium text-gray-900">添加权限</h3>
                <button class="text-gray-400 hover:text-gray-500" onclick="closeModal('addPermissionModal')">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="mt-2">
                <form>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1" for="permissionName">权限名称</label>
                        <input type="text" id="permissionName" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" placeholder="请输入权限名称">
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1" for="permissionCode">权限编码</label>
                        <input type="text" id="permissionCode" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" placeholder="请输入权限编码">
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1" for="permissionType">权限类型</label>
                        <select id="permissionType" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50">
                            <option value="menu">菜单权限</option>
                            <option value="operation">操作权限</option>
                            <option value="data">数据权限</option>
                        </select>
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1" for="parentPermission">父级权限</label>
                        <select id="parentPermission" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50">
                            <option value="">无（顶级权限）</option>
                            <option value="system">系统管理</option>
                            <option value="hotel">酒店管理</option>
                            <option value="role">角色管理</option>
                            <option value="permission">权限管理</option>
                            <option value="user">用户管理</option>
                            <option value="hotel-info">酒店信息</option>
                            <option value="room">房间管理</option>
                        </select>
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1" for="permissionDesc">权限描述</label>
                        <textarea id="permissionDesc" rows="3" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" placeholder="请输入权限描述"></textarea>
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1">状态</label>
                        <div class="flex items-center">
                            <input type="radio" id="statusEnable" name="status" value="1" class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300" checked>
                            <label for="statusEnable" class="ml-2 block text-sm text-gray-700">启用</label>
                            <input type="radio" id="statusDisable" name="status" value="0" class="ml-6 focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300">
                            <label for="statusDisable" class="ml-2 block text-sm text-gray-700">禁用</label>
                        </div>
                    </div>
                    <div class="flex justify-end mt-6">
                        <button type="button" class="bg-gray-500 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded mr-2" onclick="closeModal('addPermissionModal')">
                            取消
                        </button>
                        <button type="submit" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded">
                            确定
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- 编辑权限模态框 -->
    <div id="editPermissionModal" class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full hidden">
        <div class="relative top-20 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white">
            <div class="flex justify-between items-center mb-4">
                <h3 class="text-lg font-medium text-gray-900">编辑权限</h3>
                <button class="text-gray-400 hover:text-gray-500" onclick="closeModal('editPermissionModal')">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="mt-2">
                <form>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1" for="editPermissionName">权限名称</label>
                        <input type="text" id="editPermissionName" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" value="查看角色">
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1" for="editPermissionCode">权限编码</label>
                        <input type="text" id="editPermissionCode" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" value="role:view">
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1" for="editPermissionType">权限类型</label>
                        <select id="editPermissionType" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50">
                            <option value="menu" selected>菜单权限</option>
                            <option value="operation">操作权限</option>
                            <option value="data">数据权限</option>
                        </select>
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1" for="editParentPermission">父级权限</label>
                        <select id="editParentPermission" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50">
                            <option value="">无（顶级权限）</option>
                            <option value="system">系统管理</option>
                            <option value="hotel">酒店管理</option>
                            <option value="role" selected>角色管理</option>
                            <option value="permission">权限管理</option>
                            <option value="user">用户管理</option>
                            <option value="hotel-info">酒店信息</option>
                            <option value="room">房间管理</option>
                        </select>
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1" for="editPermissionDesc">权限描述</label>
                        <textarea id="editPermissionDesc" rows="3" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50">查看角色列表的权限</textarea>
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1">状态</label>
                        <div class="flex items-center">
                            <input type="radio" id="editStatusEnable" name="editStatus" value="1" class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300" checked>
                            <label for="editStatusEnable" class="ml-2 block text-sm text-gray-700">启用</label>
                            <input type="radio" id="editStatusDisable" name="editStatus" value="0" class="ml-6 focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300">
                            <label for="editStatusDisable" class="ml-2 block text-sm text-gray-700">禁用</label>
                        </div>
                    </div>
                    <div class="flex justify-end mt-6">
                        <button type="button" class="bg-gray-500 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded mr-2" onclick="closeModal('editPermissionModal')">
                            取消
                        </button>
                        <button type="submit" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded">
                            确定
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- 删除权限确认模态框 -->
    <div id="deletePermissionModal" class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full hidden">
        <div class="relative top-20 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white">
            <div class="flex justify-between items-center mb-4">
                <h3 class="text-lg font-medium text-gray-900">确认删除</h3>
                <button class="text-gray-400 hover:text-gray-500" onclick="closeModal('deletePermissionModal')">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="mt-2 mb-6">
                <p class="text-gray-700">确定要删除该权限吗？删除后将无法恢复，且会影响已分配该权限的角色。</p>
            </div>
            <div class="flex justify-end">
                <button type="button" class="bg-gray-500 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded mr-2" onclick="closeModal('deletePermissionModal')">
                    取消
                </button>
                <button type="button" class="bg-red-600 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
                    确定删除
                </button>
            </div>
        </div>
    </div>

    <!-- JavaScript 代码 -->
    <script>
        // 打开模态框
        function openModal(modalId) {
            document.getElementById(modalId).classList.remove('hidden');
            document.body.style.overflow = 'hidden';
        }

        // 关闭模态框
        function closeModal(modalId) {
            document.getElementById(modalId).classList.add('hidden');
            document.body.style.overflow = 'auto';
        }

        // 展开所有节点
        function expandAll() {
            const toggles = document.querySelectorAll('.tree-toggle:not(.invisible)');
            toggles.forEach(toggle => {
                const targetId = toggle.getAttribute('data-target');
                const targetElement = document.getElementById(targetId);
                const icon = toggle.querySelector('i');
                
                targetElement.style.display = 'block';
                icon.classList.remove('fa-chevron-right');
                icon.classList.add('fa-chevron-down');
            });
        }

        // 折叠所有节点
        function collapseAll() {
            const toggles = document.querySelectorAll('.tree-toggle:not(.invisible)');
            toggles.forEach(toggle => {
                const targetId = toggle.getAttribute('data-target');
                const targetElement = document.getElementById(targetId);
                const icon = toggle.querySelector('i');
                
                targetElement.style.display = 'none';
                icon.classList.remove('fa-chevron-down');
                icon.classList.add('fa-chevron-right');
            });
        }

        // 树形结构展开/折叠
        document.addEventListener('DOMContentLoaded', function() {
            const toggles = document.querySelectorAll('.tree-toggle:not(.invisible)');
            toggles.forEach(toggle => {
                toggle.addEventListener('click', function() {
                    const targetId = this.getAttribute('data-target');
                    const targetElement = document.getElementById(targetId);
                    const icon = this.querySelector('i');
                    
                    if (targetElement.style.display === 'none') {
                        targetElement.style.display = 'block';
                        icon.classList.remove('fa-chevron-right');
                        icon.classList.add('fa-chevron-down');
                    } else {
                        targetElement.style.display = 'none';
                        icon.classList.remove('fa-chevron-down');
                        icon.classList.add('fa-chevron-right');
                    }
                });
            });

            // 处理复选框级联选择
            const checkboxes = document.querySelectorAll('.tree-checkbox');
            checkboxes.forEach(checkbox => {
                checkbox.addEventListener('change', function() {
                    const isChecked = this.checked;
                    const id = this.getAttribute('data-id');
                    
                    // 如果是父级复选框，选中/取消选中所有子级
                    if (this.classList.contains('parent-checkbox')) {
                        const childCheckboxes = document.querySelectorAll(`.tree-checkbox[data-parent="${id}"]`);
                        childCheckboxes.forEach(childCheckbox => {
                            childCheckbox.checked = isChecked;
                            
                            // 处理孙级复选框
                            const childId = childCheckbox.getAttribute('data-id');
                            const grandChildCheckboxes = document.querySelectorAll(`.tree-checkbox[data-parent="${childId}"]`);
                            grandChildCheckboxes.forEach(grandChildCheckbox => {
                                grandChildCheckbox.checked = isChecked;
                            });
                        });
                    }
                    
                    // 如果是子级复选框，更新父级复选框状态
                    if (this.classList.contains('child-checkbox') || this.classList.contains('leaf-checkbox')) {
                        const parentId = this.getAttribute('data-parent');
                        if (parentId) {
                            const parentCheckbox = document.querySelector(`.tree-checkbox[data-id="${parentId}"]`);
                            if (parentCheckbox) {
                                // 检查所有同级复选框是否都被选中
                                const siblingCheckboxes = document.querySelectorAll(`.tree-checkbox[data-parent="${parentId}"]`);
                                const allChecked = Array.from(siblingCheckboxes).every(cb => cb.checked);
                                const anyChecked = Array.from(siblingCheckboxes).some(cb => cb.checked);
                                
                                parentCheckbox.checked = allChecked;
                                
                                // 如果是子级复选框，还需要处理叶子节点
                                if (this.classList.contains('child-checkbox')) {
                                    const childId = this.getAttribute('data-id');
                                    const leafCheckboxes = document.querySelectorAll(`.tree-checkbox[data-parent="${childId}"]`);
                                    leafCheckboxes.forEach(leafCheckbox => {
                                        leafCheckbox.checked = isChecked;
                                    });
                                }
                                
                                // 递归处理更上一级的父级复选框
                                if (parentCheckbox.classList.contains('child-checkbox')) {
                                    const grandParentId = parentCheckbox.getAttribute('data-parent');
                                    if (grandParentId) {
                                        const grandParentCheckbox = document.querySelector(`.tree-checkbox[data-id="${grandParentId}"]`);
                                        if (grandParentCheckbox) {
                                            const uncleCheckboxes = document.querySelectorAll(`.tree-checkbox[data-parent="${grandParentId}"]`);
                                            const allUnclesChecked = Array.from(uncleCheckboxes).every(cb => cb.checked);
                                            grandParentCheckbox.checked = allUnclesChecked;
                                        }
                                    }
                                }
                            }
                        }
                    }
                });
            });

            // 初始化折叠按钮事件
            document.querySelector('.fas.fa-compress-alt').parentElement.addEventListener('click', collapseAll);
        });

        // 添加右键菜单功能
        document.addEventListener('DOMContentLoaded', function() {
            const treeNodes = document.querySelectorAll('.tree-node');
            const contextMenu = document.createElement('div');
            contextMenu.className = 'absolute bg-white shadow-md rounded-md py-1 z-50 hidden';
            contextMenu.innerHTML = `
                <button class="w-full text-left px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" data-action="edit">编辑</button>
                <button class="w-full text-left px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" data-action="delete">删除</button>
                <button class="w-full text-left px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" data-action="add">添加子权限</button>
            `;
            document.body.appendChild(contextMenu);

            let activeNodeId = null;

            treeNodes.forEach(node => {
                node.addEventListener('contextmenu', function(e) {
                    e.preventDefault();
                    
                    // 获取当前节点ID
                    const checkbox = node.querySelector('.tree-checkbox');
                    if (checkbox) {
                        activeNodeId = checkbox.getAttribute('data-id');
                        
                        // 显示右键菜单
                        contextMenu.style.display = 'block';
                        contextMenu.style.left = `${e.pageX}px`;
                        contextMenu.style.top = `${e.pageY}px`;
                    }
                });
            });

            // 点击其他地方隐藏右键菜单
            document.addEventListener('click', function() {
                contextMenu.style.display = 'none';
            });

            // 处理右键菜单操作
            contextMenu.addEventListener('click', function(e) {
                const action = e.target.getAttribute('data-action');
                if (action && activeNodeId) {
                    if (action === 'edit') {
                        // 编辑权限
                        openModal('editPermissionModal');
                        // 这里可以添加代码，根据activeNodeId获取权限信息并填充到编辑表单中
                    } else if (action === 'delete') {
                        // 删除权限
                        openModal('deletePermissionModal');
                    } else if (action === 'add') {
                        // 添加子权限
                        openModal('addPermissionModal');
                        // 预设父级权限为当前选中的节点
                        document.getElementById('parentPermission').value = activeNodeId;
                    }
                }
                contextMenu.style.display = 'none';
            });

            // 初始化展开/折叠按钮事件
            document.querySelector('.fas.fa-expand-alt').parentElement.addEventListener('click', expandAll);
            document.querySelector('.fas.fa-compress-alt').parentElement.addEventListener('click', collapseAll);
        });

        // 搜索功能
        function searchPermissions() {
            const searchInput = document.getElementById('permissionSearch').value.toLowerCase();
            const treeNodes = document.querySelectorAll('.tree-node');
            
            if (searchInput.trim() === '') {
                // 如果搜索框为空，显示所有节点
                treeNodes.forEach(node => {
                    node.style.display = 'flex';
                });
                return;
            }
            
            // 先隐藏所有节点
            treeNodes.forEach(node => {
                node.style.display = 'none';
            });
            
            // 显示匹配的节点及其父节点
            treeNodes.forEach(node => {
                const nodeText = node.textContent.toLowerCase();
                if (nodeText.includes(searchInput)) {
                    // 显示匹配的节点
                    node.style.display = 'flex';
                    
                    // 显示父节点
                    let parent = node.parentElement;
                    while (parent && !parent.classList.contains('tree-container')) {
                        if (parent.tagName === 'LI') {
                            const parentNode = parent.querySelector('.tree-node');
                            if (parentNode) {
                                parentNode.style.display = 'flex';
                            }
                        }
                        
                        // 如果父节点有子节点列表，确保它是展开的
                        if (parent.tagName === 'LI') {
                            const toggle = parent.querySelector('.tree-toggle');
                            if (toggle) {
                                const targetId = toggle.getAttribute('data-target');
                                const targetElement = document.getElementById(targetId);
                                if (targetElement) {
                                    targetElement.style.display = 'block';
                                    const icon = toggle.querySelector('i');
                                    if (icon) {
                                        icon.classList.remove('fa-chevron-right');
                                        icon.classList.add('fa-chevron-down');
                                    }
                                }
                            }
                        }
                        
                        parent = parent.parentElement;
                    }
                }
            });
        }

        // 监听搜索框输入事件
        document.getElementById('permissionSearch').addEventListener('input', searchPermissions);

        // 初始化页面
        document.addEventListener('DOMContentLoaded', function() {
            // 默认展开所有节点
            expandAll();
        });
    </script>
</body>
</html>